import datetime,os,json,requests,time
from db import db1
sql1="select * from test_record"
res=db1.findall(sql1)
for i in res:
    name=i['name']
    url=i['url']
    params=json.loads(i['params'])
    method=i['method']
    result=i['result']
print(name,url,method,result)
res=requests.get(url)
mes=json.loads(res.text)
print(mes['code'])
flag='通过'
if mes['code']!=result:
    flag='不通过'
report={'url':url,'请求方式':method,'返回结果':result,'请求参数':params,'测试结果':flag}
print(report)
filename=datetime.datetime.now().strftime('%Y-%m-%d')
with open(os.path.join('../logs/'+filename+'.txt'),'w') as f:
    f.write(json.dumps(report,ensure_ascii=False))
print('写入成功\n写入日期:%s'%filename)
# for i in range(1,1000):
#     filename1 = datetime.datetime.now().strftime('%H:%M:%S')
#     print(filename1)
#     time.sleep(1)

